package com.emex.app.shared.data.wrapper;

import com.emex.app.shared.data.OrderPosition;
import com.emex.app.shared.data.enums.OrderPositionStatus;
import com.emex.app.shared.data.enums.OrderStatus;
import java.util.List;

/**
 * Wrapper to light order status
 *
 * @author Sergey Karavaev
 */
public class OrderStatusWrapper {

    private boolean ok = true;

    private final OrderStatus status;

    public OrderStatusWrapper(OrderStatus orderStatus, List<OrderPosition> orderPositions) {
        status = orderStatus;
        initialize(orderPositions);
    }

    private void initialize(List<OrderPosition> orderPositions) {
        if (null != orderPositions && !orderPositions.isEmpty()) {
            for (OrderPosition op : orderPositions) {
                OrderPositionStatus orderPositionStatus = OrderPositionStatus.valueOf(op.getStatus());
                if (orderPositionStatus.equals(OrderPositionStatus.DECLINED)
                        || orderPositionStatus.equals(OrderPositionStatus.RETURNED_SKLAD)
                        || orderPositionStatus.equals(OrderPositionStatus.RETURNED_SUPPLIER)) {
                    ok = false;
                }
            }
        }
    }

    public boolean isOk() {
        return ok;
    }
    
    @Override
    public String toString() {
        return status.toString();
    }
}
